import React,{ useState} from "react";
import {Modal,Button} from 'antd'

// 用来编辑新增的弹框

const LlxModal = (props) => {
/**
 * contents 主要的内容
 * btnText 按钮文字
 * isDanger 是否是删除按钮
 * title 标题
 * isDisabled 按钮是否禁用
 * width 长度
 */
  const {btnText,isDanger,title,isDisabled,width,handleOk,isEdit,link,wrapClassName} = props
  const [isModalVisible, setIsModalVisible] = useState(false);


  const showModal = async(value) => {
    await isEdit()
    setIsModalVisible(true);
  };

  const handleOkFn = async() => {
    const res = await handleOk()
    if(!res) return
    setIsModalVisible(false);
  };

  const handleCancelFn = () => {
    setIsModalVisible(false);
  };

  return (
    <>
       <Button size="small" danger={isDanger?true:false} disabled={isDisabled?true:false} type={link?'link':"primary"} onClick={showModal}>
          {btnText||'异常'}
        </Button> 
       <Modal  wrapClassName={wrapClassName}  width={width} title={title} visible={isModalVisible} onOk={handleOkFn} onCancel={handleCancelFn}>
        <div>
          {
            props.FormComponent?<props.FormComponent/>:''
          }
        </div>
      </Modal>
    </>
  );
};

export default LlxModal